﻿using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace Pku.BookStore.DAL
{
    public class BaseDAL
    {
        public static SqlDatabase DbMain = GetDb(DatabaseTypeNo.Main);
        public static SqlDatabase DbReadonly = GetDb(DatabaseTypeNo.Readonly);

        public static SqlDatabase GetDb(DatabaseTypeNo dbNo)
        {
            string dbstring = "";
#if DEBUG
            dbstring = "Test";
#endif
            switch (dbNo)
            {
                case DatabaseTypeNo.Main:
                    dbstring = "Main" + dbstring;
                    break;
                case DatabaseTypeNo.Readonly:
                    dbstring = "Readonly" + dbstring;
                    break;
                default:
                    {
                        throw new ApplicationException("数据库枚举不存在！" + dbNo.ToString());
                    }
            }
            return new SqlDatabase(ConfigurationManager.ConnectionStrings[dbstring].ConnectionString);
        }
    }
    /// <summary>
    /// 数据库连接类型
    /// </summary>
    public enum DatabaseTypeNo
    {
        /// <summary>
        /// 主库
        /// </summary>
        Main,
        /// <summary>
        /// 只读库
        /// </summary>
        Readonly
    }
}